package org.example.stream;

import org.example.entity.Fruit;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Stream;

public class Stream02 {
    // 构建流：用已有的数据生成流
    // 三种，集合，数组，对象
    // map集合需要转换成entrySet
    public static void main(String[] args) {
        List<Fruit> fruitList = Arrays.asList(
                new Fruit("草莓", "Strawberry", "浆果", "红色"),
                new Fruit("桑葚", "Mulberry", "浆果", "紫色"),
                new Fruit("杨梅", "Wax-berry", "浆果", "红色"),
                new Fruit("核桃", "Walnut", "坚果", "棕色"),
                new Fruit("花生", "Peanut", "坚果", "棕色"),
                new Fruit("蓝莓", "Blueberry", "浆果", "蓝色")
        );
        fruitList.stream().forEach(System.out::println);

        HashMap<String, String> map = new HashMap<>();
        map.put("1","2");
        map.put("3","4");
        map.entrySet().stream().forEach(System.out::println);

        Integer[][] array2D = {
                {1,2,3},
                {4,5,6},
                {7,8,9}
        };

        Arrays.stream(array2D).forEach(System.out::println);

        Stream.of(
                        new Fruit("草莓", "Strawberry", "浆果", "红色"),
                        new Fruit("桑葚", "Mulberry", "浆果", "紫色"),
                        new Fruit("杨梅", "Wax-berry", "浆果", "红色"),
                        new Fruit("核桃", "Walnut", "坚果", "棕色"),
                        new Fruit("花生", "Peanut", "坚果", "棕色"),
                        new Fruit("蓝莓", "Blueberry", "浆果", "蓝色")
                ).forEach(System.out::println);
    }
}
